<?php

/**
 * This file is part of webman.
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

use Webman\Route;

Route::group('/api/v1', function () {
  Route::group('/auth', function () {
    Route::get('/captcha', [app\controller\system\AuthController::class, "captcha"]);
    Route::post('/login', [app\controller\system\AuthController::class, "login"]);
    Route::post('/login/wexin', [app\controller\system\AuthController::class, "wexinLogin"]);
    Route::delete('/logout', [app\controller\system\AuthController::class, "logout"]);
    Route::post('/sms/code', [app\controller\system\AuthController::class, "sendSms"]);
    Route::post('/refresh-token', [app\controller\system\AuthController::class, "refreshToken"]);
    Route::post('/wx/miniapp/phone-login', [app\controller\system\AuthController::class, "wxMiniapp"]);
  });
  Route::group('/users', function () {
    Route::get('/me', [app\controller\system\UserController::class, "me"]);
    Route::put('/password', [app\controller\system\UserController::class, "setMyPassword"]);
    Route::get('/page', [app\controller\system\UserController::class, "page"]);
    Route::get('/profile', [app\controller\system\UserController::class, "getMyProfile"]);
    Route::put('/profile', [app\controller\system\UserController::class, "setMyProfile"]);
    Route::put('/mobile', [app\controller\system\UserController::class, "setMobile"]);
    Route::post('/mobile/code', [app\controller\system\UserController::class, "getMobileCode"]);
    Route::put('/email', [app\controller\system\UserController::class, "setEmail"]);
    Route::post('/email/code', [app\controller\system\UserController::class, "getEmailCode"]);
    Route::get('/options', [app\controller\system\UserController::class, "getOptions"]);
    Route::post('', [app\controller\system\UserController::class, "create"]);
    Route::get('/{id:\d+}/form', [app\controller\system\UserController::class, "get"]);
    Route::put('/{id:\d+}', [app\controller\system\UserController::class, "update"]);
    Route::delete('/{id:\d+}', [app\controller\system\UserController::class, "delete"]);
    Route::put('/{userId:\d+}/password/reset', [app\controller\system\UserController::class, "setPassword"]);
    Route::patch('/{userId:\d+}/status', [app\controller\system\UserController::class, "setStatus"]);
  });

  Route::group('/roles', function () {
    Route::get('/page', [app\controller\system\RoleController::class, "page"]);
    Route::post('', [app\controller\system\RoleController::class, "create"]);
    Route::get('/{id:\d+}/form', [app\controller\system\RoleController::class, "form"]);
    Route::get('/options', [app\controller\system\RoleController::class, "getOptions"]);
    Route::put('/{id:\d+}', [app\controller\system\RoleController::class, "update"]);
    Route::delete('/{id:\d+}', [app\controller\system\RoleController::class, "delete"]);
    Route::get('/{roleId:\d+}/menuIds', [app\controller\system\RoleController::class, "getMenuIds"]);
    Route::put('/{roleId:\d+}/status', [app\controller\system\RoleController::class, "setStatus"]);
    Route::put('/{roleId:\d+}/menus', [app\controller\system\RoleController::class, "setMenus"]);
  });

  Route::group('/menus', function () {
    Route::get('/routes', [app\controller\system\MenuController::class, "routes"]);
    Route::get('/options', [app\controller\system\MenuController::class, "options"]);
    Route::post('', [app\controller\system\MenuController::class, "create"]);
    Route::get('', [app\controller\system\MenuController::class, "get"]);
    Route::get('/{id:\d+}/form', [app\controller\system\MenuController::class, "form"]);
    Route::put('/{id:\d+}', [app\controller\system\MenuController::class, "update"]);
    Route::patch('/{id:\d+}', [app\controller\system\MenuController::class, "visible"]);
    Route::delete('/{id:\d+}', [app\controller\system\MenuController::class, "delete"]);
  });

  Route::group('/dept', function () {
    Route::get('', [app\controller\system\DeptController::class, "getTree"]);
    Route::post('', [app\controller\system\DeptController::class, "create"]);
    Route::get('/{id:\d+}/form', [app\controller\system\DeptController::class, "form"]);
    Route::put('/{id:\d+}', [app\controller\system\DeptController::class, "update"]);
    Route::get('/options', [app\controller\system\DeptController::class, "options"]);
  });

  Route::group('/dicts', function () {
    Route::get('/page', [app\controller\system\DictController::class, "page"]);
    Route::post('', [app\controller\system\DictController::class, "create"]);
    Route::get('/{dictCode:\w+}/items', [app\controller\system\DictController::class, "getItems"]);
    Route::get('/{dictCode:\w+}/items/page', [app\controller\system\DictController::class, "getItemsPage"]);
    Route::get('/{dictCode:\w+}/items/{itemId}/form', [app\controller\system\DictController::class, "itemForm"]);
    Route::post('/{dictCode:\w+}/items', [app\controller\system\DictController::class, "setItems"]);
    Route::delete('/{dictCode:\w+}/items/{itemIds}', [app\controller\system\DictController::class, "deleteItems"]);
    Route::put('/{dictCode:\w+}/items/{itemId}', [app\controller\system\DictController::class, "updateItem"]);
    Route::get('/{id:\d+}/form', [app\controller\system\DictController::class, "form"]);
    Route::put('/{id:\d+}', [app\controller\system\DictController::class, "update"]);
    Route::delete('/{id:\d+}', [app\controller\system\DictController::class, "delete"]);
  });

  Route::group('/config', function () {
    Route::get('/page', [app\controller\system\ConfigController::class, "page"]);
    Route::post('', [app\controller\system\ConfigController::class, "create"]);
    Route::get('/{id:\d+}/form', [app\controller\system\ConfigController::class, "form"]);
    Route::put('/{id:\d+}', [app\controller\system\ConfigController::class, "update"]);
    Route::delete('/{id:\d+}', [app\controller\system\ConfigController::class, "delete"]);
    Route::put('/refresh', [app\controller\system\ConfigController::class, "refresh"]);
  });

  Route::group('/logs', function () {
    Route::get('/page', [app\controller\system\LogController::class, "page"]);
    Route::get('/visit-trend', [app\controller\system\LogController::class, "visitTrend"]);
    Route::get('/visit-stats', [app\controller\system\LogController::class, "visitStatus"]);
  });

  Route::group('/notices', function () {
    Route::get('/my-page', [app\controller\system\NoticeController::class, "userNotices"]);
    Route::get('/page', [app\controller\system\NoticeController::class, "page"]);
    Route::post('', [app\controller\system\NoticeController::class, "create"]);
    Route::get('/{id:\d+}/form', [app\controller\system\NoticeController::class, "form"]);
    Route::put('/{id:\d+}', [app\controller\system\NoticeController::class, "update"]);
    Route::delete('/{ids}', [app\controller\system\NoticeController::class, "delete"]);
    Route::put('/{id:\d+}/revoke', [app\controller\system\NoticeController::class, "revoke"]);
    Route::put('/{id:\d+}/publish', [app\controller\system\NoticeController::class, "publish"]);
    Route::put('/read-all', [app\controller\system\NoticeController::class, "readAll"]);
    Route::get('/{id:\d+}/detail', [app\controller\system\NoticeController::class, "detail"]);
  });
})->middleware([
  app\middleware\JwtAuth::class
]);
